﻿namespace jzgl.Controller
{
    using jzgl.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    internal class DesStyleDB
    {
        private SqlConnection conn = null;
        private ConnDB conndb = new ConnDB();
        private DataTable table = null;
        private SysUser user = new SysUser();

        public DesStyleDB()
        {
            this.conn = this.conndb.GetConnString();
        }

        public int Add_DesStyle(DesStyle ds)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "insert into DesStyle values('" + ds._DesStyleName + "')";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_DesStyle(DesStyle ds)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from DesStyle where DesStyleId='" + ds._DesStyleId + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public DataTable Show_DesStyle()
        {
            try
            {
                try
                {
                    string sql = "select DesStyleId as '编号', DesStyleName as '风格名称' from DesStyle";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public void Show_DesStyle(ComboBox box)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from DesStyle";
                    this.conndb.comboxDataBind(box, sqlstr, "DesStyleId", "DesStyleName");
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public void Show_DesStyle(DataGridView dgv)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from DesStyle";
                    this.conndb.dgvDataBind(dgv, sqlstr);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public int Update_DesStyle(DesStyle ds)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = string.Concat(new object[] { "update DesStyle set DesStyleName='", ds._DesStyleName, "' where  DesStyleId='", ds._DesStyleId, "'" });
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }
    }
}

